#!/bin/sh
# PCP QA Test No. 787
# Frank's "slow" archive with <mark> records
# See http://oss.sgi.com/bugzilla/show_bug.cgi?id=1044
#
# Copyright (c) 2014 Ken McDonell.  All Rights Reserved.

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

status=1	# failure is the default!
trap "cd $here; rm -rf $tmp.*; exit \$status" 0 1 2 3 15

# change to true to produce detailed values in $seq_full to
# validate the interpolated values reported by pmval
#
full=true

_summary()
{
    grep '^__pmLogRead:' | wc -l | sed -e 's/ //g'
}

_filter()
{
    sed -e "s@$tmp@TMP@g"
}

pmdumplog -xz archives/bug-1044 >$tmp.tmp
echo "log records: `grep -E '^([A-Z][a-z][a-z] )|([0-2][0-9]:)' <$tmp.tmp | wc -l | sed -e 's/ //g'`"

# for full output, lines look like
# Fri Jan 10 17:58:09.600 2014  60.0.32 (hinv.ncpu): value 4
#
$full && grep '<mark>' <$tmp.tmp | LC_COLLATE=POSIX sort -k 3,3n -k 4,4 >$tmp.mark

# real QA test starts here
for metric in hinv.ncpu kernel.all.nprocs pmcd.numagents
do
    echo | tee -a $seq_full
    echo "=== $metric ===" | tee -a $seq_full
    $full && pmdumplog -zL archives/bug-1044 >>$seq_full
    $full && pmdumplog -xz archives/bug-1044 $metric | grep -E '^([A-Z][a-z][a-z] )|([0-2][0-9]:)' | LC_COLLATE=POSIX sort -k 3,3n -k 4,4 >$tmp.tmp
    $full && LC_COLLATE=POSIX sort -k 3,3n -k 4,4 $tmp.tmp $tmp.mark >>$seq_full

    echo | tee -a $seq_full
    echo "+++ forwards +++" | tee -a $seq_full
    opt='-Dlog'
    $full && opt='-Dlog,interp'
    pmval -z $opt -t 1hr -A 1hr -a archives/bug-1044 $metric 2>$tmp.err
    echo "log reads: `_summary <$tmp.err`"
    $full && cat $tmp.err >>$seq_full

    echo | tee -a $seq_full
    echo "+++ backwards +++" | tee -a $seq_full
    $full && opt='-Dlog,interp'
    src/interp1 $opt -d -s 1000 -a archives/bug-1044 -t 3600 $metric 2>$tmp.err
    $full && cat $tmp.err >>$seq_full

    echo "`echo $metric | sed -e 's/\./_/g'` = $metric;" >>$tmp.pmie
done

echo | tee -a $seq_full
echo "=== pmcd.numagents converted to discrete semantics ===" | tee -a $seq_full
echo "metric pmcd.numagents {  sem -> discrete }" >$tmp.config
pmlogrewrite -c $tmp.config archives/bug-1044 $tmp
pmval -z -Dlog -t 1hr -A 1hr -a $tmp pmcd.numagents 2>$tmp.err \
| _filter
echo "log reads: `_summary <$tmp.err`"
$full && cat $tmp.err >>$seq_full

echo
echo "=== all metrics at once ==="
pmie -z -a archives/bug-1044 -c $tmp.pmie -t 1hr -A 1hr -v -Dlog 2>$tmp.err
echo "log reads: `_summary <$tmp.err`"


# success, all done
status=0

exit
